﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MMS.Model;
using MMS.BLL;

namespace MarketMS
{
    public partial class JieSuan : Form
    {
        public List<BuyGoodsInfo> BuyList { get; set; }
        /// <summary>
        /// 标识结算是否成功
        /// </summary>
        public bool IsScuccess { get; set; }
        public JieSuan()
        {
            InitializeComponent();
        }

        double totalMoney = 0.0;
        private void JieSuan_Load(object sender, EventArgs e)
        {
            foreach (BuyGoodsInfo item in BuyList)
            {
                totalMoney += item.XiaoJi;//累加小计
            }
            txtTotalMoney.Text = totalMoney.ToString();
        }

        private void txtGiveMoney_KeyUp(object sender, KeyEventArgs e)
        {
            if (txtGiveMoney.Text != "")
            {
                double giveMoney = double.Parse(txtGiveMoney.Text);//获取输入的金额
                txtReturn.Text = (giveMoney - totalMoney).ToString();
            }
        }
        private OrderManager om = new OrderManager();
        private void btnYes_Click(object sender, EventArgs e)
        {
            //确定结算
            bool ret = om.CreateOrder(BuyList, totalMoney, 1);//TODO 后期需要获取员工编号
            if (ret == false)
            {
                MessageBox.Show("生成订单失败，请重试!");
                return;
            }
            string message = string.Format(@"结算信息如下:
实收金额：{0}
应收金额：{1}
找零：{2}", txtGiveMoney.Text, totalMoney, txtReturn.Text);
            MessageBox.Show(message);
            IsScuccess = true;//标识结算成功
            this.Close();

        }
    }
}
